#include<iostream>
#include<algorithm>
#define INT_MIN 0x80000000
using namespace std;
const int maxn = 10005;

int main(void) {
    int k;
    cin>>k;
    int num[maxn];
    int thisSum = 0,maxSum = INT_MIN;
    int thisLeft=0,thisRight=0;
    int maxLeft,maxRight;
    for(int i = 0; i < k; i++) {
        cin>>num[i];
        thisSum += num[i];
        thisRight = i;
        if(thisSum > maxSum) {
            maxSum = thisSum;
            maxLeft = thisLeft;
            maxRight = thisRight;
        }
        if(thisSum < 0) {
            thisSum = 0;
            thisLeft = i+1;
            thisRight = i+1;
        }
    }

    if(maxSum < 0) {
        printf("0 %d %d",num[0],num[k-1]);
    }
    else {
        printf("%d %d %d",maxSum,num[maxLeft],num[maxRight]);
    }

    return 0;
}